package com.niit.service.impl;

import com.niit.entity.Userorders;
import com.niit.mapper.UserordersMapper;
import com.niit.service.UserordersService;
import com.niit.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (Userorders)表服务实现类
 *
 * @author makejava
 * @since 2024-06-18 15:45:07
 */
@Service("userordersService")
public class UserordersServiceImpl implements UserordersService {
    @Resource
    private UserordersMapper userordersMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param userId 主键
     * @return 实例对象
     */
    @Override
    public Result queryById(Integer userId) {
        return Result.ok().setData(this.userordersMapper.queryById(userId));
    }

    /**
     * 全查询
     *
     * @param userorders 筛选条件
     * @return 查询结果
     */
    @Override
    public Result queryAll(Userorders userorders) {
        return Result.ok().setData(this.userordersMapper.queryAll(userorders));
    }

    /**
     * 新增数据
     *
     * @param userorders 实例对象
     * @return 实例对象
     */
    @Override
    public Result insert(Userorders userorders) {
        this.userordersMapper.insert(userorders);
        return Result.ok().setData(userorders);
    }

    /**
     * 修改数据
     *
     * @param userorders 实例对象
     * @return 实例对象
     */
    @Override
    public Result update(Userorders userorders) {
        this.userordersMapper.update(userorders);
        return Result.ok().setData(this.queryById(userorders.getUserId()));
    }

    /**
     * 通过主键删除数据
     *
     * @param userId 主键
     * @return 是否成功
     */
    @Override
    public Result deleteById(Integer userId) {
        boolean del = this.userordersMapper.deleteById(userId) > 0;
        return Result.ok().setData(del);
    }
}

